import { makeAutoObservable } from 'mobx'
import { getUserDossiersAllView, getUserDossiersAllViewOpen } from './api'
import type { getUserDossiersAllViewReq } from './interface'
import { useLocation } from 'react-router'

class Store {
    archivesInfo: getUserDossiersAllViewReq | any = {}

    constructor() {
        makeAutoObservable(this)
        this.getAllData()
    }

    getAllData = () => {
        const { user_token } = (useLocation() as any).query
        if (user_token) {
            getUserDossiersAllViewOpen({ user_token }).then(({ data }) => {
                this.archivesInfo = data
            })
        } else {
            getUserDossiersAllView().then(({ data }) => {
                this.archivesInfo = data
            })
        }
    }
}

export default Store
